home *** CD-ROM | disk | FTP | other *** search
/ CD Concept 6 / CD Concept 06.iso / mac / UTILITAIRE / Oztex / PS-files / OzTeXdict.pro < prev    next >
Text File  |  1995-01-31  |  9KB  |  274 lines

  1. % DVI-to-PS prolog used by OzTeX 1.8 with standard Mac print drivers.
  2. % Uncomment the following line to prevent a timeout error when
  3. % creating missing PK fonts.
  4.  
  5. % statusdict begin /waittimeout 0 def end
  6.  
  7. /OzTeXdict 200 dict def            % enough room for about 150 fonts
  8. OzTeXdict begin
  9.  
  10. /@setup                                % set up OzTeX
  11. { /res exch def                    % resolution (defines dots per inch)
  12.   /ht exch def                        % paper height (in dots)
  13.   /wd exch def                        % paper width (in dots)
  14.   /land wd ht gt def                % landscape orientation?
  15. } def
  16.  
  17. /newPKfont                            % create new PK font
  18. { /maxchcode exch def
  19.   /fontid exch def
  20.   fontid 7 dict def
  21.   fontid load begin
  22.       /FontType 3 def
  23.       /FontMatrix [1 0 0 -1 0 0] def
  24.       /FontBBox [0 0 1 1] def
  25.       /BitMaps maxchcode 1 add array def
  26.       /BuildChar {CharBuilder} def
  27.       /Encoding 256 array def
  28.       0 1 255 {Encoding exch /.notdef put} for
  29.       end
  30.   fontid fontid load definefont setfont
  31. } def
  32.  
  33. % The char data, a bitmap descriptor, is an array with 6 elements;
  34. % element 0 is either a hex string or an array of hex strings (the latter
  35. % is required for large PK chars with more than 65535 hex digits).
  36.  
  37. /ch-image    {ch-data 0 get dup type /stringtype ne {N get /N N 1 add def} if
  38.                 } def                            % hex string
  39. /ch-width    {ch-data 1 get} def        % the number of pixels across
  40. /ch-height    {ch-data 2 get} def        % the number of pixels tall
  41. /ch-xoff        {ch-data 3 get} def        % number of pixels to left of origin
  42. /ch-yoff        {ch-data 4 get} def        % number of pixels below origin
  43. /ch-advw        {ch-data 5 get} def        % advance width
  44.  
  45. % The following character builder looks up the char data in the BitMaps array
  46. % and paints the character.
  47.  
  48. /CharBuilder                                % image one char
  49. { /ch-code exch def                        % save the char code
  50.   /font-dict exch def                    % and the font dict
  51.   /ch-data font-dict /BitMaps get
  52.   ch-code get def
  53.   /N 0 def
  54.       ch-advw 0
  55.       ch-xoff neg ch-height ch-yoff sub 1 sub neg    % -xo , -(ht-yo-1)
  56.       ch-width ch-xoff sub 1 sub ch-yoff                % (wd-xo-1) , yo
  57.   setcachedevice
  58.       ch-width ch-height true
  59.       [1 0 0 -1 ch-xoff ch-yoff]        % bitmap sent top to bottom
  60.       {ch-image}
  61.   imagemask
  62. } def
  63.  
  64. /sf {setfont} def                            % set current font
  65.  
  66. /dc                                            % define new character
  67. { /ch-code exch def
  68.   /ch-data exch def
  69.   currentfont /BitMaps get ch-code ch-data put
  70.   currentfont /Encoding get ch-code
  71.   dup (   ) cvs cvn put                    % generate unique name
  72. } bind def
  73.  
  74. /@bop0                                        % begin page n
  75. { pop                                            % throw away page number
  76.  
  77.   % Determine printing scale.
  78.  
  79.   0 0 transform /y0 exch def /x0 exch def
  80.   res res transform
  81.   /ydiff exch y0 sub abs def
  82.   /xdiff exch x0 sub abs def
  83.   /yscale ydiff res div def            % used below and in @bsp
  84.   /xscale xdiff res div def            % ditto
  85.  
  86.   % For aligning rules, make sure ALL values in CTM are integers.
  87.   % But only do so if printing at or near 100% scale, otherwise
  88.   % an "undefinedresult" error might occur.
  89.  
  90.   xscale 1.0 sub abs .001 lt yscale 1.0 sub abs .001 lt and
  91.   { matrix currentmatrix
  92.     dup dup 0 get round cvi 0 exch put
  93.     dup dup 1 get round cvi 1 exch put
  94.     dup dup 2 get round cvi 2 exch put
  95.     dup dup 3 get round cvi 3 exch put
  96.     dup dup 4 get round cvi 4 exch put
  97.     dup dup 5 get round cvi 5 exch put
  98.     setmatrix
  99.   } if
  100.  
  101.   % r is used to typeset a rule. Some adjustment may be needed for
  102.   % different printer models; test results on page 18 in nasty.dvi.
  103.  
  104.   land                                        % landscape?
  105.   { /r                                        % set a wd by ht rule at h,v
  106.     { newpath
  107.       1 add moveto                        % move to h,v+1
  108.       /ht exch 1 sub def                % reduce height by 1
  109.       /wd exch 1 sub def                % ditto for width
  110.       wd 0 rlineto
  111.       0 ht neg rlineto
  112.       wd neg 0 rlineto
  113.       fill
  114.     } bind def
  115.   }
  116.   { /r                                        % set a wd by ht rule at h,v
  117.     { newpath
  118.       moveto                                % move to h,v
  119.       /ht exch 1 sub def                % reduce height by 1
  120.       /wd exch 1 sub def                % ditto for width
  121.       wd 0 rlineto
  122.       0 ht neg rlineto
  123.       wd neg 0 rlineto
  124.       fill
  125.     } bind def
  126.   } ifelse
  127.  
  128. } def
  129.  
  130. /mtrx 6 array def
  131.  
  132. /@bop1                                        % begin typesetting page n
  133. { pop                                            % throw away page number
  134.   mtrx currentmatrix pop                % for rotating TeX material
  135. } def
  136.  
  137. /@eop                                            % end page n
  138. { pop                                            % throw away page number
  139.  
  140.   % Use following line to help set max length of OzTeXdict.
  141.   % OzTeXdict length 10 string cvs print (\r) print flush
  142. } def
  143.  
  144. % h and s are used to typeset downloaded bitmap fonts.
  145.  
  146. /h {exch 0 rmoveto show} bind def    % move right by dh and show (...)
  147.  
  148. /s {3 1 roll moveto show} bind def    % move to h,v and show (...)
  149.  
  150. % H and S are used to typeset PostScript fonts.
  151. % We can't use relative horizontal positioning because the advance widths in
  152. % a PostScript font are not integers and rounding errors would accumulate.
  153.  
  154. /H {exch v moveto show} bind def        % move to h,v and show (...)
  155.  
  156. /S                                                % ditto, and save v position
  157. { 3 1 roll
  158.   1 add                                        % v+1 to match baseline of bitmap fonts
  159.   dup /v exch def
  160.   moveto show
  161. } bind def
  162.  
  163. % Following 2 procedures are invoked as the result of \special{file}.
  164. % Unlike @bepsf, we have no BoundingBox info, so we must use initgraphics
  165. % and make a risky assumption about which way to rotate if landscape.
  166.  
  167. /@bsp
  168. { /vmag exch def                            % vertical scaling
  169.   /hmag exch def                            % horizontal scaling
  170.   moveto                                        % move to h,v
  171.   /prespecialVM save def                % save showpage, TeX procedures etc.
  172.   userdict begin                            % push userdict on dict stack
  173.   /showpage {} def                        % user does not have to remove showpage
  174.   currentpoint transform
  175.   initgraphics itransform translate    % move 0,0 to h,v
  176.   hmag vmag scale
  177.   xscale yscale scale                    % calculated in @bop0
  178.   land { -90 rotate } if                % rotate axes if landscape
  179. } bind def
  180.  
  181. /@esp
  182. { end                                            % pop userdict
  183.   prespecialVM restore                    % restore saved showpage value etc
  184. } bind def
  185.  
  186. % Following 2 procedures are invoked as the result of \special{epsf=file}.
  187.  
  188. /@bepsf
  189. { /lly exch def                            % LLy for BoundingBox
  190.   /llx exch def                            % LLx for BoundingBox
  191.   /vmag exch def                            % vertical scaling
  192.   /hmag exch def                            % horizontal scaling
  193.   /vpos exch def                            % v pos of \special box
  194.   /hpos exch def                            % h pos of \special box
  195.   /prespecialVM save def                % save showpage, TeX procedures etc
  196.   userdict begin                            % push userdict on dict stack
  197.   /showpage {} def                        % user does not have to remove showpage
  198.   hpos vpos translate                    % move 0,0 to h,v
  199.   hmag vmag scale                            % scale BoundingBox
  200.   llx neg lly neg translate            % move LLx,LLy to h,v
  201. } bind def
  202.  
  203. /@eepsf
  204. { end                                            % pop userdict
  205.   prespecialVM restore                    % restore saved showpage value etc
  206. } bind def
  207.  
  208. % Here is the code to handle bitmaps generated by PICT/PNTG \specials.
  209.  
  210. /@bitmap
  211. { /vmag exch def                            % vertical scaling
  212.   /hmag exch def                            % horizontal scaling
  213.   /vres exch def                            % vertical resolution of bitmap
  214.   /hres exch def                            % horizontal resolution of bitmap
  215.   /ht exch def                                % height
  216.   /wd exch def                                % width
  217.   /hexstring ht string def
  218.   gsave
  219.      1 add translate                        % set origin to h,v+1
  220.      res hres div wd mul hmag mul
  221.      res vres div ht mul vmag mul neg scale
  222.      wd ht true
  223.      [ wd 0 0 ht neg 0 ht ]
  224.      { currentfile hexstring readhexstring pop }
  225.      imagemask
  226.   grestore
  227. } def
  228.  
  229. % Here are the definitions needed to handle PostScript fonts.
  230.  
  231. /namestr 60 string def                    % for names
  232. /numstr 12 string def                    % for numbers
  233.  
  234. /newPSfont                                    % create new PS font
  235. { /fontname exch def                        % printer font name
  236.   /mag exch def                            % DVI mag
  237.   /scaledpts exch def                    % font size in scaled pts
  238.  
  239.   % Use scaledpts and mag to calculate font size in device dots.
  240.   scaledpts 16#10000 div                % scaled pts to pts
  241.   res mul 72.27 div                        % pts to device dots
  242.   mag 1000 div mul                        % scale by mag/1000
  243.   /dotsize exch def
  244.   /done false def
  245.   
  246.   % If fontname starts with "Slanted-" then construct slanted font.
  247.   fontname namestr cvs (Slanted-) anchorsearch
  248.   { pop cvn findfont [1 0 .167 -1 0 0] makefont dotsize scalefont
  249.     /done true def
  250.   }{ pop } ifelse
  251.  
  252.   % Other nice tricks can be included here if you build the required
  253.   % fonts and add appropriate printer font names to your config file.
  254.   % fontname namestr cvs (Extended-) anchorsearch
  255.   % { pop cvn findfont [1.2 0 0 -1 0 0] makefont dotsize scalefont
  256.   %   /done true def
  257.   % }{ pop } ifelse
  258.   
  259.   done not
  260.   { fontname findfont [1 0 0 -1 0 0] makefont dotsize scalefont
  261.   } if
  262.  
  263.   % Modified font dictionary is on stack, so remember it for later setfont
  264.   % via a unique name that is the concatenation of fontname and scaledpts.
  265.   fontname length scaledpts numstr cvs length add
  266.   /newname exch string def
  267.   newname 0 fontname namestr cvs putinterval
  268.   newname fontname length scaledpts numstr cvs putinterval
  269.   newname cvn exch def
  270. } bind def
  271.  
  272. % Do NOT include matching "end" for "OzTeXdict begin" in this file.
  273. % OzTeX will add "end" after downloading font info.
  274.